import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import HomePage from '../views/Home/HomePage.vue'
import LoginView from '../views/Home/LoginView.vue'

const modulesRoutes: Array<RouteRecordRaw> = []

// 自动加载路由配置
const modulesFiles = require.context('./modules', false, /.+\.ts$/)
modulesFiles.keys().forEach((modulePath: string) => {
  modulesFiles(modulePath).default && modulesRoutes.push(...modulesFiles(modulePath).default)
})

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'LoginView',
    component: LoginView
  },
  {
    path: '/',
    name: 'home',
    component: HomePage,
    children: [
      ...modulesRoutes
    ]
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router
